home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Snippets / New Venus / src / ImageViews.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-01  |  3.5 KB  |  104 lines  |  [TEXT/CWIE]

  1. /*
  2.  ***********************************************************************
  3.  *
  4.  *                    Full-color (full-graw) picture items
  5.  *                (Sub)windows displaying some picture in 2D/3D        
  6.  *
  7.  * These items are considered User Items in a dialog, and should supply
  8.  * functions how to process hits and perform custom drawing
  9.  *
  10.  ***********************************************************************
  11.  */
  12.  
  13. #include "Dialog.h"
  14.  
  15. class IMAGE;                        // Opaque class
  16.  
  17.  
  18. class ViewerPosition
  19. {
  20. public:
  21.   int xe, ye;                                        // Location of an observation point
  22.   int gx, gy;                                        // Gaze vector (of size |g|=1<<14)
  23.   enum { g_unit = 1<<14 };                            // |g|, size of the gaze vector
  24.   ViewerPosition(const int _xe, const int _ye, const int _gx, const int _gy);
  25.  
  26.   void do_one_turn(void);                            // Perform one step of circling around
  27. private:  
  28.   int xc, yc;                                // Point to fly around
  29.   float rx, ry;                                // current r = E-C, precisely!
  30.   const float g_per_rad;                    // |g|/flying_radius
  31.   enum { flying_radius = 40};
  32. };
  33.  
  34. struct ProjectionParameters
  35. {
  36.   int ze;                                        // Elevation of the view point
  37.   int beta;                                        // Local coordinates scaling factor
  38.   int Ou, Ov;                                    // Origin of the local coordinate ref Pt
  39.   int z_cutoff, elevation_factor;                // Coefficients to determine elevation from
  40.                                                   // the map's "elevation code"
  41. };
  42.  
  43.                                     // Picture view in 2d
  44. class ImageView : public UserItem, public OffScreenBuffer
  45. {
  46.   const IMAGE& image;                                // Image to view
  47.   ViewerPosition viewer_pos;                        // Where the viewer is at
  48. public:
  49.   ImageView(const IMAGE& image);
  50.   void bind(const ModelessDialog& the_dialog, const int item_no);            // Late constructor
  51.   void draw(void) { OffScreenBuffer::draw(rect); draw_mark(); }        // Custom-draw this item  
  52.  
  53.   void draw_mark(void);                            // Draw a mark of the plane  
  54.   void undraw_mark(void);                        // Erase the mark of the plane  
  55.   const ViewerPosition& where_is_viewer(void) const        { return viewer_pos; }
  56.                                                       // Perform one step of circling around
  57.   void do_one_turn(void)        { undraw_mark(); viewer_pos.do_one_turn(); draw_mark(); }
  58.   
  59.   enum { elevation_color_CLUT_id = 128 };            // How to colorize map pixels
  60. };
  61.  
  62.  
  63.                                     // Picture view in 3d
  64. class ThreeDView : public UserItem, public OffScreenBuffer
  65. {
  66.   const IMAGE& map;                        // Image to view
  67.   const ViewerPosition& viewer_pos;        // To get the view parameters from
  68.   const ProjectionParameters& projection_parms;
  69.  
  70.   void project(void);                    // Draw a projection in an offscreen
  71.                                         // world
  72.  
  73.                                 // A class to handle one scanline of the view plane
  74.   class OneViewScanline
  75.   {
  76.     friend class ScanLineAccess;        // needed for a member function kludge
  77.   public:
  78.     struct ScanPoint {                    // A scan point at some given u
  79.       int v;                            // visible elevation (note, PowerPC prefers ints to short)
  80.       int color;                        // color of a point (taken from the map)
  81.     };
  82.   
  83.     OneViewScanline(const int _width);
  84.     ~OneViewScanline(void);    
  85.  
  86.     int q_width(void) const                { return width; }
  87.     void print(const card i=0) const;                // print a scanline point
  88.  
  89.   private:
  90.     const int width;                        // width of a scanline
  91.     ScanPoint * const scan_points;            // scanpoints of a scanline
  92.         
  93.   };
  94.   
  95.   OneViewScanline scanline1, scanline2;        // Two working scanlines
  96.  
  97. public:
  98.   ThreeDView(const IMAGE& image_map, const ViewerPosition& viewer_pos,
  99.                const ProjectionParameters& projection_parms);
  100.   void bind(const ModelessDialog& the_dialog, const int item_no);            // Late constructor
  101.   void draw(void) { OffScreenBuffer::draw(rect); }                            // Custom-draw this item  
  102.   void re_project(void)                 { project(); draw(); }
  103. };
  104.